<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Promise微任务处理机制</title>
  </head>
  <body></body>
  <script>
    //pending 准备阶段
    //resolved 成功状态
    //rejected 拒绝状态
    //同步>异步微任务>异步宏任务
    //宏任务队列
    setTimeout(() => {
      console.log("hdcms");
    }, 1000);

    //Promise会产生微任务队列，优先于宏任务队列处理
    new Promise((resolve, reject) => {
      resolve();
      //promise内部是同步的，then才是异步
      console.log("promise");
    })
      .then(
        (value) => {
          console.log("成功业务处理1");
        },
        (reason) => {
          console.log("失败业务处理1");
        }
      )
      .then(
        (value) => {
          console.log("成功业务处理2");
        },
        (reason) => {
          console.log("失败业务处理2");
        }
      );

    //主线程同步任务最优先
    console.log("houdun");
  </script>
</html>
